import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Map;

import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.Source;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;

public class Test
{
  public static void main(String[] arg)
  throws Exception
  {
    String     url = "http://127.0.0.1:8080/P1-ABC-Library-EJB/LibraryManagerBean?wsdl";
    String      ns = "librarymanager";
    QName     name = new QName(ns, "LibraryManagerService");
    QName     port = new QName(ns, "port");
    String content = "<ns2:alleBoeken xmlns:ns2=\""+ns+"\"/>";

    Service service = Service.create(name);
    service.addPort(port, SOAPBinding.SOAP11HTTP_BINDING, url);

    Dispatch<Source> dispatch = service.createDispatch(port, Source.class, Service.Mode.PAYLOAD);
    
    BindingProvider bindingProvider = (BindingProvider) dispatch;

    Map<String, Object> map = bindingProvider.getRequestContext();
    map.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
    map.put(BindingProvider.SOAPACTION_URI_PROPERTY, "hello");
    map.put(BindingProvider.USERNAME_PROPERTY, "eric");
    map.put(BindingProvider.PASSWORD_PROPERTY, "geheim");
    
    
    Source input = new StreamSource(new ByteArrayInputStream(content.getBytes()));
    Source response = dispatch.invoke(input);

    Transformer trans = TransformerFactory.newInstance().newTransformer();
    StreamResult result = new StreamResult(new ByteArrayOutputStream());
    trans.transform(response, result);
    ByteArrayOutputStream baos = (ByteArrayOutputStream)result.getOutputStream();
    System.out.println(new String(baos.toByteArray()));
  }
}
